//
//  MHMyCompanyRootController.m
//  M-Saler
//
//  Created by Teresa on 2020/5/21.
//  Copyright © 2020 Teresa. All rights reserved.
//

#import "MHMyCompanyRootController.h"
#import "MHMyCompanyTableRootCell.h"
#import "MHCompanyDetailController.h"
#import "MHMyCompanyRequest.h"
#import "MHMyCompanyModel.h"

@interface MHMyCompanyRootController ()

@property(strong,nonatomic)MHMyCompanyModel *model;

@end

@implementation MHMyCompanyRootController

- (void)viewDidLoad {
    [super viewDidLoad];
    [MHMyCompanyTableRootCell registerToTableView:self.tableView];
    [self fetchData];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self configNavBarRed];
    self.title = @"我的公司";
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.contentInset = UIEdgeInsetsMake(12, 0, 0, 0);
}

-(void)fetchData{
    MHMyCompanyRequest *req = [MHMyCompanyRequest new];
    req.salesman_id = [MHUserModel userModel].theID;
    BLOCKSELF;
    [req asyncRequestWithsuccessHandler:^(BaseResponse *response) {
        blockSelf.model = response.data;
        [blockSelf.tableView reloadData];
    } failHandler:^(BaseResponse *response) {
        [[HUDHelper sharedInstance]tipMessage:response.message];
    }];
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 53;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MHMyCompanyTableRootCell *cell = [tableView dequeueReusableCellWithIdentifier:[MHMyCompanyTableRootCell nameOfClass] forIndexPath:indexPath];
    cell.model = self.model;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    MHCompanyDetailController *newVC = [[MHCompanyDetailController alloc]initWithNibName:MHCompanyDetailController.nameOfClass bundle:nil];
    newVC.model = self.model;
    [self.navigationController pushViewController:newVC animated:YES];
}

@end
